package com.stlm2.controller;

import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.PutObjectRequest;
import com.stlm2.core.redis.RedisClient;
import com.stlm2.dems.dao.DdmGoodsDao;
import com.stlm2.dems.dao.GoodSpecificationDao;
import com.stlm2.dems.dao.PriceRecordDao;
import com.stlm2.dems.entity.DdmGoods;
import com.stlm2.dems.entity.GoodSpecification;
import com.stlm2.dems.entity.PriceRecord;
import com.stlm2.dems.service.DdmGoodsService;
import com.stlm2.dems.service.GoodSpecificationService;
import com.stlm2.dems.user.dao.UserRoleDao;
import com.stlm2.dems.user.entity.AllRole;
import com.stlm2.dems.user.entity.UserRole;
import com.stlm2.util.ImageUtil;
import com.stlm2.util.UploadImage;
import com.stlm2.util.codecontent.CodeContent;
import org.junit.Test;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import javax.annotation.Resource;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

/**
 * 作者: fcy
 * 时间: 2017/5/27
 * 描述：测试后台开发环境
 */
@Controller
@RequestMapping("/testC")
public class TestController {

    @Resource
    private GoodSpecificationDao goodSpecificationDao;
    @Resource
    private DdmGoodsService ddmGoodsService;
    @Resource
    private PriceRecordDao priceRecordDao;

    @Resource
    private DdmGoodsDao ddmGoodsDao;
    @ResponseBody
    @RequestMapping(value="/jiage.json",produces="application/json;charset=UTF-8")
    public  String jiage(){
        GoodSpecification goodSpecification=new GoodSpecification();
        List<GoodSpecification> goodSpecificationList=goodSpecificationDao.queryPageView(-1,-1,goodSpecification).getRecords();
        for (GoodSpecification goodSpecification1:goodSpecificationList){
            PriceRecord priceRecord1=new PriceRecord();
            priceRecord1.setGoodsId(goodSpecification1.getId());
            priceRecord1.setSpeciflcationId(goodSpecification1.getId());
            priceRecord1=priceRecordDao.getRecentlyOne(priceRecord1);
            if(priceRecord1==null ){
                PriceRecord priceRecord=new PriceRecord();
                priceRecord.setGoodsId(goodSpecification.getGoodId());
                priceRecord.setPrice(goodSpecification.getMemberPrice());
                priceRecord.setSpeciflcationId(goodSpecification.getId());
                priceRecord.setUpdateTime(new Date());
                priceRecord.setUpdateUserId(1);
                priceRecordDao.add(priceRecord);
            }
        }
        System.out.print("執行成功");
        return CodeContent.getModelByCode(1, "", null);
    }


    @ResponseBody
    @RequestMapping(value="/q91.json",produces="application/json;charset=UTF-8")
    public  String q91(){
        GoodSpecification goodSpecification=new GoodSpecification();
        List<GoodSpecification> goodSpecificationList=goodSpecificationDao.queryPageView(-1,-1,goodSpecification).getRecords();
        for (GoodSpecification goodSpecification1:goodSpecificationList){
            String parameter =goodSpecification1.getParameter();
            parameter=parameter.replace("https://m.9ji.com","");
            goodSpecification1.setParameter(parameter);
            goodSpecificationDao.modify(goodSpecification1);
        }
        List<DdmGoods> ddmGoodsList=ddmGoodsDao.queryPageView(-1,-1,new DdmGoods()).getRecords();
        for (DdmGoods ddmGoods:ddmGoodsList){
            String parameter =ddmGoods.getParameter();
            parameter=parameter.replace("https://m.9ji.com","");
            ddmGoods.setParameter(parameter);
            String detailsImg=ddmGoods.getDetailsImg();
            detailsImg=detailsImg.replace("https://m.9ji.com","");
            ddmGoods.setDetailsImg(detailsImg);
            ddmGoodsDao.modify(ddmGoods);
        }
        System.out.print("執行成功");
        return CodeContent.getModelByCode(1, "", null);

    }


}
